﻿using HCD.Hcd.Dtos;
using HCD.Hcd;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using HCD.User.Dtos;

namespace HCD.Web.Controllers.ApiControllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HCDController : EnterpriseControllerBase
    {
        public IHcdAppService HcdAppService { get; set; }

        /// <summary>
        /// 通讯录科室列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<AddressBookDept>> GetAddressBookDeptList()
        {
            var re = new List<AddressBookDept> {
                new AddressBookDept {
                    DeptCode = "0001",
                    DeptName = "心血管内科"}
            };
            return re;
        }

        /// <summary>
        /// 获取通讯录用户列表
        /// </summary>
        /// <param name="DeptCode">科室代码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<AddressBookUser>> GetAddressBookUserList(string DeptCode = "0001")
        {
            return new List<AddressBookUser> {
                new AddressBookUser {
                    UserId = "D001",
                    UserName = "艾总",
                    Sex = "女",
                    Title = "主治医师",
                    PhoneNumber = "15356132529"}
            };
        }

        /// <summary>
        /// 获取用户筛选列表(For左侧筛选列表)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<UserScreeningDto>> GetUserScreeningList()
        {
            return new List<UserScreeningDto>
            {
                new UserScreeningDto
                {
                    ScreeningName = "我的筛选1",
                    Count = 50
                }
            };
        }

        /// <summary>
        /// 获取患者来源科室列表(For左侧筛选列表)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SourceDeptDto>> GetSourceDeptList()
        {
            return await HcdAppService.GetSourceDeptList();
        }

        /// <summary>
        /// 获取标签列表(For左侧筛选列表)
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous, HttpGet]
        public async Task<List<LabelTypeDto>> GetLabelTypeList()
        {
            //string str = this.HttpContext.Request.Headers["accept"];
            //this.HttpContext.Request.Headers["accept"] = "application/xml";
            //string str1 = this.HttpContext.Request.Headers["accept"];
            return await HcdAppService.GetLabelTypeList();
            //return new List<LabelTypeDto>
            //{
            //    new LabelTypeDto
            //    {
            //        LabelTypeCode = "01",
            //        LabelTypeName = "围手术期",
            //        Count = 26
            //    },
            //    new LabelTypeDto
            //    {
            //        LabelTypeCode = "03",
            //        LabelTypeName = "口服降压药",
            //        Count = 12
            //    }
            //};
        }

        /// <summary>
        /// 获取管理分型列表(For左侧筛选列表)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ManagePartingDto>> GetManagementPartingList()
        {
            return await HcdAppService.GetManagePartingList();
        }

        /// <summary>
        /// 获取在管病人列表（主界面）
        /// </summary>
        /// <param name="Type">查询类型</param>
        /// <param name="TypeValue">查询值</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<HcdMasterDto>> GetHcdPatientList(string Type, string TypeValue)
        {
            return await HcdAppService.GetHcdPatientList(Type, TypeValue);
        }

        /// <summary>
        /// 获取病人所有标签
        /// </summary>
        /// <param name="PatientId">病人Id</param>
        /// <param name="VisitId">就诊标识</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<HcdPatLabelsDto>> GetHcdPatLabelsList(string PatientId, string VisitId)
        {
            return await HcdAppService.GetHcdPatLabelsList(PatientId, VisitId);
        }

        /// <summary>
        /// 更新消息状态为已读
        /// </summary>
        /// <param name="lstMessage">未读消息列表</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> UpdateMessageStatus([FromBody] List<HcdMessageEditDto> lstMessage)
        {
            return await HcdAppService.UpdateMessageStatus(lstMessage);
        }

        /// <summary>
        /// 设置病人为随访病人
        /// </summary>
        /// <param name="item">病人主记录的物理主键</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdatePatientIntoFollowUp(HcdMasterFollowUpDto item)
        {
            return await HcdAppService.UpdatePatientIntoFollowUp(item);
        }

        /// <summary>
        /// 将病人移除院内管理
        /// </summary>
        /// <param name="item">病人主记录的物理主键</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> SetPatientOutofManagement(HcdMasterRemoveDto item)
        {
            return await HcdAppService.SetPatientOutofManagement(item);
        }
    }
}